{include header}
<div class="wrapper">
    {include header_menu}

    {include left_menu}
    <div class="main-container">
        <div class="padding-md">


            <style>

            .table-striped>tbody>tr{
                    cursor: pointer;
            }
            </style>
            <script>
            (function(){

            });
            function edit_forum(obj){
                var i=0;
                $("#edit0").val('');
                $("#edit1").val('');

                $(obj).find('td').each(function(e){
                    if(!i){
                        $("#edit"+(i++)).val($(this).text());

                    }
                    $("#edit"+(i++)).val($(this).text());


                })
            }
            function edit_user(obj,id,type,b){



                $.post(window.location.pathname,{gn:3,id:id,b:b,type:type},function(e){
                    if(e.error){
                        var bb = b ? 0 : 1;
                        if(b){
                            $(obj).attr('onclick',"edit_user(this,"+id+",'"+type+"',"+ bb +")");
                            $(obj).text("禁止");
                            $(obj).removeClass('btn-success').addClass('btn-danger');
                        }else{
                            $(obj).attr('onclick',"edit_user(this,"+id+",'"+type+"',"+ bb +")");
                            $(obj).text("允许");
                            $(obj).removeClass('btn-danger').addClass('btn-success');
                        }

                    }
                },'json')
            }

            </script>
            <table class="table table-striped table-bordered m-top-md" id="dataTable" >
				<thead>
					<tr class="bg-dark-blue">
						<th>用户组 ID</th>
						<th>用户组 名称</th>
                        <th>允许发帖</th>
                        <th>允许评论</th>
                        <th>允许@</th>
                        <th>允许上传图片</th>
                        <th>允许删除帖子</th>
                        <th>操作</th>
					</tr>
				</thead>
				<tbody>
                    {foreach $data as $v}
                    <tr onclick="edit_forum(this)">
                        <td>{$v.id}</td>
                        <td>{$v.name}</td>
                        <td><button type="button" onclick="edit_user(this,{$v.id},'thread',{$v['json']['thread'] ? 1 : 0})" class="btn btn-{if $v['json']['thread']}success btn-xs">允许{else}danger btn-xs">禁止{/if}</button></td>
                        <td><button type="button" onclick="edit_user(this,{$v.id},'post',{$v['json']['post'] ? 1 : 0})" class="btn btn-{if $v['json']['post']}success btn-xs">允许{else}danger btn-xs">禁止{/if}</button></td>
                        <td><button type="button" onclick="edit_user(this,{$v.id},'mess',{$v['json']['mess'] ? 1 : 0})" class="btn btn-{if $v['json']['mess']}success btn-xs">允许{else}danger btn-xs">禁止{/if}</button></td>
                        <td><button type="button" onclick="edit_user(this,{$v.id},'upload',{$v['json']['upload'] ? 1 : 0})" class="btn btn-{if $v['json']['upload']}success btn-xs">允许{else}danger btn-xs">禁止{/if}</button></td>
                        <td><button type="button" onclick="edit_user(this,{$v.id},'del',{$v['json']['del'] ? 1 : 0})" class="btn btn-{if $v['json']['del']}success btn-xs">允许{else}danger btn-xs">禁止{/if}</button></td>
                        <td>
                            <button type="button" class="btn btn-danger btn-xs">删除</button>
                        </td>
                    </tr>
                    {/foreach}


				</tbody>
			</table>
            <div class="alert alert-danger alert-custom alert-dismissible" role="alert">
		    	<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
		     	<i class="fa fa-times-circle m-right-xs"></i> <strong>警告!</strong> 添加用户组 ID 请勿用 0 零,管理员ID与游客ID 不建议修改! 用户组ID 只允许整数
		    </div>
            <div class="row">
            <div class="col-md-6">
                <div class="smart-widget m-top-lg widget-dark-blue">
    				<div class="smart-widget-header">
    					添加用户组
    					<span class="smart-widget-option">
    						<span class="refresh-icon-animated">
    							<i class="fa fa-circle-o-notch fa-spin"></i>
    						</span>

                            <a href="#" class="widget-collapse-option" data-toggle="collapse">
                                <i class="fa fa-chevron-up"></i>
                            </a>


                        </span>
    				</div>
    				<div class="smart-widget-inner">
    					<div class="smart-widget-body">
                            <h2>注意ID不可重复!</h2>
                            <section>
    		                    <p></p>
    		                </section>
    						<form  method="post">
                                <input type="hidden" name="gn" value="1">

    							<div class="form-group">
    								<label for="">用户组 ID</label>
    								<input type="text" name="id" class="form-control" >
    							</div>
                                <div class="form-group">
    								<label for="">用户组 名称</label>
    								<input type="text" name="name" class="form-control" >
    							</div>

    							<button type="submit" class="btn btn-success btn-sm">提交</button>
    						</form>
    					</div>
    				</div><!-- ./smart-widget-inner -->
    			</div>
            </div>
            <div class="col-md-6">
                <div class="smart-widget m-top-lg widget-dark-blue">
    				<div class="smart-widget-header">
    					编辑用户组
    					<span class="smart-widget-option">
    						<span class="refresh-icon-animated">
    							<i class="fa fa-circle-o-notch fa-spin"></i>
    						</span>

                            <a href="#" class="widget-collapse-option" data-toggle="collapse">
                                <i class="fa fa-chevron-up"></i>
                            </a>


                        </span>
    				</div>
    				<div class="smart-widget-inner">
    					<div class="smart-widget-body">
                            <h2>1默认是管理员,不建议修改</h2>
                            <section>
    		                    <p></p>
    		                </section>
    						<form  method="post">
                                <input type="hidden" name="gn" value="2">
                                <input type="hidden" name="iid" id="edit0">

    							<div class="form-group">
    								<label for="">用户组 ID</label>
    								<input name="id" id="edit1" type="text" class="form-control" >
    							</div>
                                <div class="form-group">
    								<label for="">用户组 名称</label>
    								<input name="name" id="edit2" type="text" class="form-control" >
    							</div>


    							<button type="submit" class="btn btn-success btn-sm">提交</button>
    						</form>

    					</div>
    				</div><!-- ./smart-widget-inner -->
    			</div>
            </div>
            </div>

        </div><!-- ENd box  -->

    </div>
</div>
{include footer}
